package pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import service.Document;

/**
 * Created by zuoxiao
 * on 2019/6/22.
 */
 @Component
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class Student implements BeanNameAware, BeanFactoryAware, ApplicationContextAware {

    @Value("#{person.firstName+' '+(person.lastName?:'Yi')}")
    String name;

    @Value("#{28-3}")
    int age;

    @Value("male")
    String sex;


    @Autowired
    Document document;

    @Autowired
    Address address;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                ", document=" + document.toString() +
                ", address=" + address.toString() +
                '}';
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("call method setBeanName of BeanNameAware!");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("call method setBeanFactory of BeanFactoryAware!");

    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("call method setApplicationContext of ApplicationContextAware!");

    }

    public void init() {
        System.out.println("call method init!");

    }

    public void destroy() {
        System.out.println("call method destroy!");
    }
}
